package cn.itcast.export.controller;

import cn.itcast.export.domain.Export;
import cn.itcast.export.domain.ExportProductExample;
import cn.itcast.export.service.ExportProductService;
import cn.itcast.export.service.ExportService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Controller
@RequestMapping("/export")
public class ExportController {

	@Autowired
	private HttpServletRequest request;

	@Autowired
	private ExportService exportService;

	@Autowired
	private ExportProductService exportProductService;

	@RequestMapping("/list")
	public String list() {
		List list = exportService.findAll(null);
		request.setAttribute("list",list);
		return "list";
	}

	@RequestMapping("/detail")
	public String detail(String id) {
		Export export = exportService.findById(id);
		request.setAttribute("export",export);
		ExportProductExample example = new ExportProductExample();
		ExportProductExample.Criteria criteria = example.createCriteria();
		criteria.andEidEqualTo(id);
		List list = exportProductService.findAll(example);
		request.setAttribute("list",list);
		return "detail";
	}

	@RequestMapping("verify")
	public String verify(String id,Integer state) {
		Export export = exportService.findById(id);
		export.setState(3);
		export.setReason("审核成功");
		exportService.update(export);
		return "redirect:/export/list";
	}
}
